function [a,b,c,d]=homework3(options,power)
%function [a,b,c,d]=homework3()
%blast bpsk does way better than everything, how does it never get errors for 2x2
%unitary group codes have very high bit error rates, which is not supposed to happen...
%are these performances in line with what we expect?
%graph performance of these vs signal to noise ratio (variables a,b,c,d in homework3alldata.mat)
%need conclusion for writeup
%unitary cyclic group 4,3 is terrible

if(nargin<1)
options=[1 2 3 4];
power=100;	%total power being transmitted
end

noise=1;	%noise at each receiver
rho=power/noise;
correl1=0.6;
sample_words={'Hello World' 'whats up doc' 'gone fishin' '867-5309 Jenny' 'Twilight zone' 'random word2007' 'myemail@address.com', 'moreworrds', 'somemisspelled', 'JUST TESTING', 'unitary_group_code', 'xklqapksad'}; 

word=char(sample_words(ceil(rand()*length(sample_words))));

training=20;

%part A
if(length(find(options==1)) > 0)
n=2;
[s1,byte_sequence1]=transmit_bpsk(word2bin(word),n);
[s2,byte_sequence2]=transmit_qpsk_gray(word2bin(word),n);
h_corr=correlated_channel(n,n,correl1,correl1);
h_uncorr=correlated_channel(n,n,0,0);
v=noise*randn(n,1) + j*noise*randn(n,1);
h_corr_hat=channel_estimation(h_corr,noise,rho,n,n,training,v);
h_uncorr_hat=channel_estimation(h_uncorr,noise,rho,n,n,training,v);
v_ala=noise*randn(n,2) + j*noise*randn(n,2);
a(1)=blast_accuracy(byte_sequence1,hw3_director(1,h_corr,h_corr,s1,v,noise,rho,n,n));
a(2)=blast_accuracy(byte_sequence1,hw3_director(1,h_uncorr,h_uncorr,s1,v,noise,rho,n,n));
a(3)=blast_accuracy(byte_sequence1,hw3_director(1,h_corr,h_corr_hat,s1,v,noise,rho,n,n));
a(4)=blast_accuracy(byte_sequence1,hw3_director(1,h_uncorr,h_uncorr_hat,s1,v,noise,rho,n,n));
a(5)=blast_accuracy(byte_sequence2,hw3_director(2,h_corr,h_corr,s2,v_ala,noise,rho,n,n));
a(6)=blast_accuracy(byte_sequence2,hw3_director(2,h_uncorr,h_uncorr,s2,v_ala,noise,rho,n,n));
a(7)=blast_accuracy(byte_sequence2,hw3_director(2,h_corr,h_corr_hat,s2,v_ala,noise,rho,n,n));
a(8)=blast_accuracy(byte_sequence2,hw3_director(2,h_uncorr,h_uncorr_hat,s2,v_ala,noise,rho,n,n));
end


%part B
if(length(find(options==2)) > 0)
nt=4;
nr=1;
v=noise*randn(nr,1) + j*noise*randn(nr,1);
h_corr=correlated_channel(nr,nt,correl1,correl1);
h_uncorr=correlated_channel(nr,nt,0,0);
h_corr_hat=channel_estimation(h_corr,noise,rho,nt,nr,training,v);
h_uncorr_hat=channel_estimation(h_uncorr,noise,rho,nt,nr,training,v);
v=noise*randn(nr,8) + j*noise*randn(nr,8);
[s3,byte_sequence3]=transmit_qamsixteen(word2bin(word),nt);
b(1)=blast_accuracy(byte_sequence3,hw3_director(3,h_corr,h_corr,s3,v,noise,rho,nt,nr));
b(2)=blast_accuracy(byte_sequence3,hw3_director(3,h_uncorr,h_uncorr,s3,v,noise,rho,nt,nr));
b(3)=blast_accuracy(byte_sequence3,hw3_director(3,h_corr,h_corr_hat,s3,v,noise,rho,nt,nr));
b(4)=blast_accuracy(byte_sequence3,hw3_director(3,h_uncorr,h_uncorr_hat,s3,v,noise,rho,nt,nr));
end

%part C
if(length(find(options==3)) > 0)
n=3;
h_corr=correlated_channel(n,n,correl1,correl1);
h_uncorr=correlated_channel(n,n,0,0);
v=noise*randn(n,1) + j*noise*randn(n,1);
h_corr_hat=channel_estimation(h_corr,noise,rho,n,n,training,v);
h_uncorr_hat=channel_estimation(h_uncorr,noise,rho,n,n,training,v);
[s4,byte_sequence4]=transmit_bpsk(word2bin(word),n);
[s5,byte_sequence5]=transmit_qamsixteen(word2bin(word),n);
c(1)=blast_accuracy(byte_sequence4,hw3_director(1,h_corr,h_corr,s4,v,noise,rho,n,n));
c(2)=blast_accuracy(byte_sequence4,hw3_director(1,h_uncorr,h_uncorr,s4,v,noise,rho,n,n));
c(3)=blast_accuracy(byte_sequence4,hw3_director(1,h_corr,h_corr_hat,s4,v,noise,rho,n,n));
c(4)=blast_accuracy(byte_sequence4,hw3_director(1,h_uncorr,h_uncorr_hat,s4,v,noise,rho,n,n));
v=noise*randn(n,4) + j*noise*randn(n,4);;
c(5)=blast_accuracy(byte_sequence5,hw3_director(4,h_corr,h_corr,s5,v,noise,rho,n,n));
c(6)=blast_accuracy(byte_sequence5,hw3_director(4,h_uncorr,h_uncorr,s5,v,noise,rho,n,n));
c(7)=blast_accuracy(byte_sequence5,hw3_director(4,h_corr,h_corr_hat,s5,v,noise,rho,n,n));
c(8)=blast_accuracy(byte_sequence5,hw3_director(4,h_uncorr,h_uncorr_hat,s5,v,noise,rho,n,n));
end


%part D
if(length(find(options==4)) > 0)
nt=2;
nr=1;
h_corr=correlated_channel(nr,nt,correl1,correl1);
h_uncorr=correlated_channel(nr,nt,0,0);
v=noise*randn(nr,1) + j*noise*randn(nr,1);
[s6,byte_sequence6]=transmit_bpsk(word2bin(word),nt);
[s7,byte_sequence7]=transmit_bpsk(word2bin(word),nt);
%qpsk has two bits per s, and we have two transmitters, thus to get a rate of 1 we send one qpsk symbol every 2 instants, 
%which means treat it like one transmit antennas
[s8,byte_sequence8]=transmit_qpsk_gray(word2bin(word),nt-1);
[s9,byte_sequence9]=transmit_qpsk_gray(word2bin(word),nt-1);
d(1)=blast_accuracy(byte_sequence6,hw3_director(5,h_corr,h_corr,s6,v,noise,rho,nt,nr));
d(2)=blast_accuracy(byte_sequence6,hw3_director(5,h_uncorr,h_uncorr,s6,v,noise,rho,nt,nr));
d(3)=blast_accuracy(byte_sequence7,hw3_director(6,h_corr,h_corr,s7,v,noise,rho,nt,nr));
d(4)=blast_accuracy(byte_sequence7,hw3_director(6,h_uncorr,h_uncorr,s7,v,noise,rho,nt,nr));
d(5)=blast_accuracy(byte_sequence8,hw3_director(7,h_corr,h_corr,s8,v,noise,rho,nt,nr));
d(6)=blast_accuracy(byte_sequence8,hw3_director(7,h_uncorr,h_uncorr,s8,v,noise,rho,nt,nr));
d(7)=blast_accuracy(byte_sequence9,hw3_director(8,h_corr,h_corr,s9,v,noise,rho,nt,nr));
d(8)=blast_accuracy(byte_sequence9,hw3_director(8,h_uncorr,h_uncorr,s9,v,noise,rho,nt,nr));
end

